package FilePanel;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.io.File;
import java.util.Observable;
import java.util.Observer;

import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

import FilePanel.controls.ControlButton;
import FilePanel.controls.ControlChooser;
import FilePanel.controls.ControlField;
import FilePanel.controls.ControlList;

public class FilePanelControl implements Observer {
	
	public FilePanelModel model;
	public FilePanelUI view;
	public ControlButton cb;
	public ControlChooser cc;
	public ControlField cf;
	public ControlList cl;
	
	/**
	 * default constructor
	 * @param model 
	 * @param view
	 * @param cb
	 * @param cc
	 * @param cf
	 * @param cl
	 */
	public FilePanelControl(FilePanelModel model, FilePanelUI view,
			ControlButton cb, ControlChooser cc, ControlField cf, ControlList cl) {
		super();
		this.model = model;
		this.view = view;
		this.cb = cb;
		this.cc = cc;
		this.cf = cf;
		this.cl = cl;
	}

	/**
	 * gets the model
	 * @return the model
	 */
	public FilePanelModel getModel() {
		return model;
	}

	/**
	 * gest the view
	 * @return view the view
	 */
	public FilePanelUI getView() {
		return view;
	}
	
	/**
	 * Enables the button or not
	 * @param enabled
	 */
	public void buttonEnabled(boolean enabled){
		this.cb.setEnabled(enabled);
	}
	
	/**
	 * sets the text of the model
	 * @param selectedIndex
	 */
	public void setSelectedIndex(int[] selectedIndex) {
		this.model.setSelectedIndex(selectedIndex);
	}


	@Override
	public void update(Observable arg0, Object arg1) {
		view.repaint();
		view.validate();
	}

	/**
	 * sets the root of the file chosen
	 * @param f the file
	 */
	public void setRoot(File f) {
		model.setRoot(f);
	}
	
	/**
	 * gets the root chosen
	 * @return model the root of the model
	 */
	public File getRoot(){
		return model.getRoot();
	}

	/**
	 * sets the text of the controlfield
	 * @param path
	 */
	public void setText(String path) {
		cf.setText(path);
		
	}

}
